home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-20 | 2.9 KB | 116 lines | [TEXT/CWIE] |
- // ===========================================================================
- // UException.h ©1994 Metrowerks Inc. All rights reserved.
- // ===========================================================================
- //
- // Exception Handling
- //
- // CodeWarrior now supports "real" C++ Exception Handling, so the
- // old macros map to the C++ syntax for exceptions.
- //
- // However, it is still useful to use the Throw_() macro instead
- // of "throw" for debugging purposes. If you #define Debug_Throw
- // you enable the debugging options for monitoring throws.
- // See the file "UDebugging.h" for details.
- //
- // Exception Codes
- //
- // The exception handling macros all used type ExceptionCode
- // when throwing. An ExceptionCode is a signed 32-bit integer.
-
- #pragma once
-
- #include <UDebugging.h>
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- // Exception codes
-
- typedef long ExceptionCode;
-
- enum {
- err_NilPointer = 'nilP',
- err_AssertFailed = 'asrt'
- };
-
-
- // Exception Handling Macros
- // These now map to the "real" Exception Handling syntax
-
- #define Try_ try
- #define Catch_(err) catch(ExceptionCode err)
- #define EndCatch_
- #define Throw(err) throw (ExceptionCode)(err)
-
-
- // Useful macros for signaling common failures
-
-
- // This macro avoids evaluating "err" twice by assigning
- // its value to a local variable.
-
- #define ThrowIfOSErr_(err) \
- do { \
- OSErr __theErr = err; \
- if (__theErr != noErr) { \
- Throw_(__theErr); \
- } \
- } while (false)
-
- #define ThrowOSErr_(err) Throw_(err)
-
- #define ThrowIfNil_(ptr) \
- do { \
- if ((ptr) == nil) Throw_(err_NilPointer); \
- } while (false)
-
- #define ThrowIfNULL_(ptr) \
- do { \
- if ((ptr) == nil) Throw_(err_NilPointer); \
- } while (false)
-
- #define ThrowIfResError_() ThrowIfOSErr_(ResError())
- #define ThrowIfMemError_() ThrowIfOSErr_(MemError())
-
- #define ThrowIfResFail_(h) \
- do { \
- if ((h) == nil) { \
- OSErr __theErr = ResError(); \
- if (__theErr == noErr) { \
- __theErr = resNotFound; \
- } \
- Throw_(__theErr); \
- } \
- } while (false)
-
- #define ThrowIfMemFail_(p) \
- do { \
- if ((p) == nil) { \
- OSErr __theErr = MemError(); \
- if (__theErr == noErr) __theErr = memFullErr; \
- Throw_(__theErr); \
- } \
- } while (false)
-
- #define ThrowIf_(test) \
- do { \
- if (test) Throw_(err_AssertFailed); \
- } while (false)
-
- #define ThrowIfNot_(test) \
- do { \
- if (!(test)) Throw_(err_AssertFailed); \
- } while (false)
-
- #define FailOSErr_(err) ThrowIfOSErr_(err)
- #define FailNIL_(ptr) ThrowIfNil_(ptr)
-